/**
 * 
 */
package co.fitstart.coach.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.stereotype.Service;

import com.demo2do.core.persistence.annotation.Dynamic;
import com.demo2do.core.service.impl.GenericServiceImpl;
import com.demo2do.core.utils.DateUtils;

import co.fitstart.coach.dao.MessageDao;
import co.fitstart.coach.service.MessageService;
import co.fitstart.entity.principal.Principal;
import co.fitstart.entity.principal.PrincipalMessage;

/**
 * @author downpour
 *
 */
@Service("messageService")
public class MessageServiceImpl extends GenericServiceImpl<PrincipalMessage> implements MessageService {
    
    @Dynamic
    private MessageDao messageDao;
    
    /* (non-Javadoc)
     * @see co.fitstart.coach.service.MessageService#countNewMessage(co.fitstart.common.entity.system.Principal)
     */
    public int countNewMessage(Principal principal) {
        
        return messageDao.countNewMessage(principal, DateUtils.getFirstMonthDay(new Date()));
    }

    /* (non-Javadoc)
     * @see co.fitstart.coach.service.MessageService#listMessages(co.fitstart.common.entity.system.Principal)
     */
    public List<PrincipalMessage> listMessages(Principal principal) {
        
        return messageDao.list(principal, DateUtils.getFirstMonthDay(new Date()));
    }

    /* (non-Javadoc)
     * @see co.fitstart.coach.service.MessageService#updateMessageStatus(co.fitstart.common.entity.system.PrincipalMessage)
     */
    public void updateMessageStatus(PrincipalMessage principalMessage) {
        genericDaoSupport.update(principalMessage.read());
    }

}
